//
//  PlayingViewController.m
//  QuicklyPlay
//
//  Created by 你的温柔是我唯一沉溺 on 15/11/11.
//  Copyright © 2015年 OPteam. All rights reserved.
//

#import "PlayingViewController.h"
#import <MediaPlayer/MediaPlayer.h>

@interface PlayingViewController ()
{
    MPMoviePlayerViewController *_moviePlayVC;
}


@end

@implementation PlayingViewController
- (void)viewDidLoad {
    [super viewDidLoad];
  
     //[[UIApplication sharedApplication] setStatusBarHidden:YES];
  
   
    [self playVideo];
    
}




-(void) playVideo {
    
    _moviePlayVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:self.getModel.m3u8_url]];
    
    
    [_moviePlayVC.moviePlayer prepareToPlay];
    

    [self presentMoviePlayerViewControllerAnimated:_moviePlayVC];
   // [_moviePlayVC supportedInterfaceOrientations];
    
    
    //_moviePlayVC.view.transform = CGAffineTransformMakeRotation(M_PI / 2);
    
    
    
    [_moviePlayVC.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
    
    _moviePlayVC.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    
    
    [self.view addSubview:_moviePlayVC.view];
    
    _moviePlayVC.moviePlayer.shouldAutoplay = YES;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:_moviePlayVC.moviePlayer];
    
    
    
}




-(void)movieFinished:(NSNotification *)notify
{
    MPMoviePlayerController *movieVC = [notify object];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:movieVC];
    
    [self dismissViewControllerAnimated:NO completion:nil];
    
}




-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscapeRight;
}



-(BOOL)shouldAutorotate {
    return YES;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
}


@end
